﻿using AutoMapper;
using B.S.Base.ErrorCode;
using B.S.Base.Moain.Entities;
using B.S.Base.Write.Api.Application.Command.Products;
using B.S.Base.Write.Api.Application.Command.Shops;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.Base.Write.Api.Controllers
{
    /// <summary>
    /// Api控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ShopController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<ShopController> logger;

        public ShopController(IMediator mediator, ILogger<ShopController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 商品添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<object>> AddShop(AddShopCommand request, CancellationToken cancellationToken)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 商品信息添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<object>> AddProduct(AddProductCommand request, CancellationToken cancellationToken)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 商品信息修改
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<APIResult<object>> Handle(UpdateProductCommand request, CancellationToken cancellationToken)
        {
            return mediator.Send(request);
        }
        /// <summary>
         /// 商品信息删除
         /// </summary>
         /// <param name="request"></param>
         /// <param name="cancellationToken"></param>
         /// <returns></returns>
        [HttpDelete]
        public Task<APIResult<object>> Handle(DelProductCommand request, CancellationToken cancellationToken)
        {
            return mediator.Send(request);
        }
    }
}
